/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author predator
 */
public class PenjualanToko {

    private String kodepenjualan;
    private String kodebarang;
    private Integer jumlah;
    private Integer harsatuan;
    private Integer hartot;
    private String tgl_jual;

    public Integer getHarsatuan() {
        return harsatuan;
    }

    public void setHarsatuan(Integer harsatuan) {
        this.harsatuan = harsatuan;
    }

    public Integer getHartot() {
        return hartot;
    }

    public void setHartot(Integer hartot) {
        this.hartot = hartot;
    }

    public PenjualanToko() {
    }

    public void setKodepenjualan(String kode_penjualan) {
        this.kodepenjualan = kode_penjualan;
    }

    public void setKodebarang(String kode_barang) {
        this.kodebarang = kode_barang;
    }

    public void setJumlah(Integer jumlah) {
        this.jumlah = jumlah;
    }

    public void setTgl_jual(String tgl_jual) {
        this.tgl_jual = tgl_jual;
    }

    public String getKodepenjualan() {
        return kodepenjualan;
    }

    public String getKodebarang() {
        return kodebarang;
    }

    public Integer getJumlah() {
        return jumlah;
    }

    public String getTgl_jual() {
        return tgl_jual;
    }

    public List lihatpenjualan(String kodepenjualan, String tgl_jual) throws SQLException {
        List sjual = new ArrayList();
//        Connection conn = DataBaseConnection.open("jdbc:oracle:thin:@localhost:1521:xe", "hr", "12345");
        Connection conn = DataBaseConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl", "mhs115314009", "mhs115314009");
        String retrieveQuery = "select * from PENJUALANTOKO where kode_pembelian='" + kodepenjualan + "' and tgl_jual='" + tgl_jual + "'";
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(retrieveQuery);
        while (rs.next()) {
            PenjualanToko jualx = new PenjualanToko();
            jualx.setKodebarang(rs.getString("kode_barang"));
            jualx.setJumlah(Integer.parseInt(rs.getString("jumlah")));
            jualx.setHarsatuan(Integer.parseInt(rs.getString("hrga_brg")));
            jualx.setHartot(Integer.parseInt(rs.getString("hartot")));
            jualx.setTgl_jual(rs.getString("tgl_jual"));
            jualx.setKodepenjualan(rs.getString("kode_pembelian"));
            sjual.add(jualx);
        }
        conn.commit();
        return sjual;
    }
}
